﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using Miris.HumanMilkAnalyser.DataModel;
using Miris.HumanMilkAnalyser.Service.Validation;

namespace Miris.HumanMilkAnalyser.WPF.ValidationRules
{
    public class AnalysisItemUsageValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var itemValidator = new AnalysisItemValidator();

            var item = new AnalysisItem
            {
                ItemUsage = value.ToString()
            };

            if (!itemValidator.CheckRequiredItemUsage(item))
            {
                return new ValidationResult(false, itemValidator.GetError(AnalysisItemValidator.ItemUsageErrorKey));
            }

            return ValidationResult.ValidResult;
        }
    }

    public class AnalysisItemDietaryRecommendationValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var itemValidator = new AnalysisItemValidator();

            var item = new AnalysisItem
            {
                DietaryRecommendation = value.ToString()
            };

            if (!itemValidator.CheckRequiredDietaryRecommendation(item))
            {
                return new ValidationResult(false, itemValidator.GetError(AnalysisItemValidator.DietaryRecommendationErrorKey));
            }

            return ValidationResult.ValidResult;
        }
    }
}
